<template>
    <div class="bg-content">
        <div style="background-color: white;">
            <u-search placeholder="请输入登录账号" shape="square" v-model="searchKeyword" @search="onSearch" @custom="onSearch"></u-search>
            <u-cell-group>
                <u-cell-item v-for="(item, index) of userList" :key="item.id" :title="item.username" :arrow="true"
                             @click="select(item)"></u-cell-item>
            </u-cell-group>
        </div>

        <div style="padding-top: 10px; padding-bottom: 10px;">
            <u-loadmore :status="pagination.status" bg-color="#eeeeee"/>
        </div>
    </div>
</template>

<script>
    import {CommonUtil} from "../../../dev/core/utils/common.util";
    import {SysUserService} from "../../../dev/services/sys-user.service";

    export default {
        data: function () {
            return {
                searchKeyword: '',
                communityId: '',
                userList: [],
            }
        },
        onShow() {
        },
        methods: {
            onSearch(event) {
                const _self = this;
                this.searchKeyword = CommonUtil.trim(this.searchKeyword);
                if (!_self.searchKeyword && !_self.communityId) {
                    CommonUtil.alert("请输入查询关键字");
                    return;
                }
                this.doRefresh(this.userList);
            },
            /*
            _self.navigateTo(`/pages/common/sys-user-select/index`, null, {
                    callback: (result => {

                    })
                })
            */
            select(item) {
                const _self = this;
                if (_self.objParams.callback) {
                    // 自定义回调函数，在回调函数中处理。
                    _self.objParams.callback(item);
                } else {
                    // 默认将值赋予哪些属性
                    _self.objParams.userId = item.id;
                    _self.objParams.username = item.username;
                }
                CommonUtil.toastNavigateBack();
            },
            /**
             * 加载更多数据中
             * @param infiniteScroll
             */
            doInfinite(infiniteScroll) {
                const _self = this;
                new SysUserService().findTableList({
                    pagination: _self.pagination,
                    data: {
                        username: _self.searchKeyword,
                        communityId: _self.communityId,
                        status: '1',
                        deleted: 0
                    }
                }).then(result => {
                    _self.pagination.refreshPage(result);
                    _self.userList = [..._self.userList, ...result.list];
                });
            }
        },
    }
</script>
